package com.chlitina.store.common.web;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.chlitina.store.common.config.Global;
import com.chlitina.store.common.oss.OSSServer;

/**
 * 文件上传
 * @author lvbo
 *
 */

@Controller
@RequestMapping(value = Global.ADMIN_PATH + "/common/upload")
public class UploadServlet extends BaseController {
	@ResponseBody
	@RequestMapping(value = "picture")
	public String upload(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
		response.setContentType("application/json; charset=UTF-8");
		String fileUrl = "";
		try {
			fileUrl = OSSServer.save(file);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "{'image':'"+ fileUrl+"'}";
	}
}
